# Copyright (c) 2021 Presto Labs Pte. Ltd.
# Author: daniel

import datetime
import json
import sys

from coin.base.timestamp import get_timestamp
from coin.flow.topic_record import TopicRecordReader, TopicRecordWriter
from coin.proto.coin_strategy_pb2 import StrategyLog
import google.protobuf.json_format as json_format


def need_remove(record):
 pb = StrategyLog()
 pb.ParseFromString(record.data)
 data = json_format.MessageToDict(pb, preserving_proto_field_name=True)
 if data['type'] == 'PNL_BALANCE' and data['pnl_balance']['total'] == 8656.15090667174:
   print(data)
   return True
 if data['type'] == 'OG_LOG' and data['og_log']['type'] == 'BALANCE':
   balances = data['og_log']['balance'].get('each_balance')
   if balances:
     for each in balances:
       if each['total'] == 41111.436394129996:
         print(data)
         return True
 return False


def main(src_file, dst_file):
  reader = TopicRecordReader(src_file)
  writer = TopicRecordWriter(dst_file)
  for record in reader.read_records():
    if need_remove(record):
      continue
    writer.write_record(record)


if __name__ == '__main__':
  main(sys.argv[1], sys.argv[2])
